<!DOCTYPE html>
<html>
    <head id="Head1">
        <title>
            Tesdo Admin
        </title>
        <?php
        require_once dirname(__FILE__) . '/includes/head.php';
        ?>
        <script type="text/javascript">
            function confirmDelete(form_id) {
                if (confirm('Are you sure?')) {
                    document.getElementById(form_id).submit();
                }
            }
        </script>
    </head>
    <body>
        <?php
        include_once dirname(dirname(__FILE__)) . '/shared/common.php';
        require_once dirname(__FILE__) . '/includes/script.php';
        require_once dirname(__FILE__) . '/includes/header.php';
        require_once dirname(__FILE__) . '/layers/dal/journal_dal.php';
//        var_dump($_FILES);
        $allowedExts = array("gif", "jpeg", "jpg", "png");
        $temp = explode(".", $_FILES["file"]["name"]);
        $extension = end($temp);
//        echo $extension . ' ' . $temp;

        if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png")) && in_array($extension, $allowedExts)) {
            echo "Dgwsgwoeglwegijonwekognowingpkmwepomheo";
            if ($_FILES["file"]["error"] > 0) {
                echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
            } else {
                echo "Upload: " . $_FILES["file"]["name"] . "<br>";
                echo "Type: " . $_FILES["file"]["type"] . "<br>";
                echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
                echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
                if (file_exists("upload/" . $_FILES["file"]["name"])) {
                    echo $_FILES["file"]["name"] . " already exists. ";
                } else {

                    move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
                    echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
                }
            }
        } else {
//            echo "Invalid file";
        }

        if (!empty($_POST['deleteAction'])) {
            $journal_id = 0;
            if (!empty($_POST['journal_id'])) {
                $journal_id = $_POST['journal_id'];
            }
            deleteJournal($journal_id);
        }

        if (!empty($_POST['btnSave'])) {
            $t_journal_id = 0;
            if (!empty($_POST['a_journal_id'])) {
                $t_journal_id = $_POST['a_journal_id'];
            }
            if (!empty($_POST['a_title'])) {
                $t_title = $_POST['a_title'];
            }
            if (!empty($_POST['a_printISSN'])) {
                $t_printISSN = $_POST['a_printISSN'];
            }
            if (!empty($_POST['a_onlineISSN'])) {
                $t_onlineISSN = $_POST['a_onlineISSN'];
            }
            if (!empty($_POST['a_publisher'])) {
                $t_publisher = $_POST['a_publisher'];
            }
            if (!empty($_POST['a_shortDescription'])) {
                $t_shortDescription = $_POST['a_shortDescription'];
            }
            if (!empty($_POST['a_fileUploadJournal'])) {
                $t_fileUploadJournal = $_POST['a_fileUploadJournal'];
            }

            add_journal($t_journal_id, $t_title, $thumb, $t_shortDescription, $t_printISSN, $t_onlineISSN, $t_publisher, $photo, date("Y-m-d H:i:s"));
        }
        $journal_id = 0;
        if (!empty($_GET['id'])) {
            $journal_id = $_GET['id'];
            $journal = getJournal($journal_id);
//            var_dump($journal);
        }
        ?>

        <div>
            <div class="content-box-outer">
                <div class="content-box-right">
                </div>
                <div class="content-box-left">
                    <h1>Publication &amp; Journals</h1>

                    <div class="MessageArea">
                        <span id="cphAdmin_lblMsg">-</span>
                    </div>
                    <form action="thesis.php" method="POST" name="pdf" enctype="multipart/form-data">
                        <div>
                            <input name="a_journal_id" value="<?php echo $journal_id; ?>" type="hidden" id="cphAdmin_txtJournalID" style="width:400px;">
                            <div class="TitleArea"><b>Title: </b></div>
                            <div class="textBoxArea">
                                <input name="a_title" value="<?php echo $journal['Title']; ?>" type="text" id="cphAdmin_txtTitle" style="width:400px;">
                            </div>
                            <div class="TitleArea"><b>Print ISSN: </b></div>
                            <div class="textBoxArea">
                                <input name="a_printISSN" value="<?php echo $journal['PrintISSN']; ?>" type="text" id="cphAdmin_txtPrintISSN" style="width:200px;">
                            </div>
                            <div class="TitleArea"><b>Online ISSN: </b></div>
                            <div class="textBoxArea">
                                <input name="a_onlineISSN" value="<?php echo $journal['OnlineISSN']; ?>" type="text" id="cphAdmin_txtOnlineISSN" style="width:200px;">
                            </div>
                            <div class="TitleArea"><b>Publisher: </b></div>
                            <div class="textBoxArea">
                                <input name="a_publisher" value="<?php echo $journal['Publish']; ?>" type="text" id="cphAdmin_txtPublisher" style="width:400px;">
                            </div>
                            <div class="TitleArea"><b>Short Description: </b></div>
                            <div class="textBoxArea">
                                <textarea name="a_shortDescription" rows="2" cols="20" id="cphAdmin_txtShortDescription" style="height:150px;width:500px;">
<?php echo $journal['ShortDescription']; ?>
                                </textarea>
                            </div>
                            <div class="TitleArea"><b>Thumb: </b></div>
                            <div class="textBoxArea">
                                <input type="file" name="a_fileUploadJournal" id="cphAdmin_FileUploadJournal"><img id="cphAdmin_imgJournal" src="">
                            </div>
                            <div class="TitleArea"><b>.</b></div>
                            <div class="textBoxArea">
                                <input type="submit" name="btnSave" value="Save" id="cphAdmin_btnSave" class="buttonDesign">
                                <input type="submit" name="btnClear" value="Clear" id="cphAdmin_btnClear" class="buttonDesign">
                                <input type="submit" name="btnCancel" value="Cancel" id="cphAdmin_btnCancel" class="buttonDesign">
                            </div>
                        </div>
                    </form>
                    <br clear="all"><br>
                    <h1>Manage Journals</h1>
                    <div>
                        <div>

                            <table cellspacing="0" cellpadding="4" rules="cols" id="cphAdmin_gvJournal" style="color:Black;background-color:White;border-color:#DEDFDE;border-width:1px;border-style:None;width:988px;border-collapse:collapse;">
                                <tbody><tr style="color:White;background-color:#6B696B;font-weight:bold;">
                                        <th scope="col">Journal Title</th><th scope="col">Print ISSN</th><th scope="col">Online ISSN</th><th scope="col">Short Description</th><th align="center" scope="col">Thumb</th><th scope="col">Actions</th>
                                    </tr>
<?php
$journals = getAllJournals();
//var_dump($journals);
foreach ($journals as $i => $item) {
    ?>
                                        <tr style="background-color:#F7F7DE;">
                                            <td style="width:300px;"><?php echo $item['Title']; ?></td><td style="width:100px;"><?php echo $item['PrintISSN']; ?></td><td style="width:100px;"><?php echo $item['OnlineISSN']; ?></td><td>&nbsp;</td><td align="center">
                                                <a href="../layout/images/journal_images/<?php echo $item['Thumb']; ?>" target="_blank">
                                                    <img id="cphAdmin_gvJournal_imgPIC_0" src="../layout/images/journal_images/<?php echo $item['Thumb']; ?>" style="height:80px;width:60px;">
                                                </a>
                                            </td><td align="center">
                                                <a href="thesis.php?id=<?php echo $item['JournalID']; ?>">
                                                    <input type="image" name="buttonEdit" id="cphAdmin_gvJournal_ImageButtonEdit_0" title="Edit" src="layout/images/edit.png" style="width:15px;">
                                                </a>
                                                <form action="thesis.php" method="POST" name="delete_form_<?php echo $item['JournalID']; ?>">
                                                    <input name="deleteAction" value="1" type="hidden" id="cphAdmin_txtJournalID">
                                                    <input name="journal_id" value="<?php echo $item['JournalID']; ?>" type="hidden" id="cphAdmin_txtJournalID">
                                                    <input type="image" name="buttonDelete" id="cphAdmin_gvJournal_ImageButtonDelete_0" title="Delete" src="layout/images/delete.png" onclick="confirmDelete('delete_form_<?php echo $item['JournalID']; ?>');" style="width:15px;">
                                                </form>

                                            </td>
                                        </tr>
    <?php
}
?>
                                    <tr align="right" style="color:Black;background-color:#F7F7DE;">
                                        <td colspan="6">
                                            <table>
                                                <tbody>
                                                    <tr>
                                                        <td>
                                                            <span>1</span>
                                                        </td>
                                                        <td><a href="javascript:__doPostBack('ctl00$cphAdmin$gvJournalSubDetail','Page$2')" style="color:Black;">2</a></td>
                                                        <td><a href="javascript:__doPostBack('ctl00$cphAdmin$gvJournalSubDetail','Page$3')" style="color:Black;">3</a></td>
                                                        <td><a href="javascript:__doPostBack('ctl00$cphAdmin$gvJournalSubDetail','Page$4')" style="color:Black;">4</a></td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                </tbody></table>
                        </div>
                    </div>
                </div>
            </div>

        </div>

<?php
require_once dirname(__FILE__) . '/includes/footer.php';
?>
    </body>
</html>
